package com.nantai.jiafang.nantaijiafang.base;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import static android.content.Context.INPUT_METHOD_SERVICE;

/**
 * Created by Administrator on 2017/11/7.
 */

public abstract class BaseFragment<B extends ViewDataBinding> extends Fragment {
    private B binding;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding= DataBindingUtil.inflate(inflater,setlayoutid(),container,false);
        initUI(binding);
        return binding.getRoot();
    }
    public abstract int setlayoutid();
    public abstract void initUI(B binding);
    public void toast(String s){
        Toast.makeText(getContext(), s, Toast.LENGTH_SHORT).show();
    }
    public void toast(int s){
        Toast.makeText(getContext(), String.valueOf(s), Toast.LENGTH_SHORT).show();
    }
    public void toast(float s){
        Toast.makeText(getContext(), String.valueOf(s), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(getActivity().getCurrentFocus()!=null)
        {
            ((InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow((getActivity().getCurrentFocus().getWindowToken()),InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}
